3.6 条件判断处理2(np.where)
import pandas as pd,numpy as np
s=pd.Series([ 100,76,84,60,78 ])
df=pd.read_excel( "测试素材.学生成绩.xlsx","成绩表" )
t=np.where(s>70, "已达标","未达标" )
df["说明"]=np.where(df.iloc[:,2:]> 500 , "录取","复读" )
print (t)
print (df)
返回:
['已达标' '已达标' '已达标' '未达标' '已达标']
姓名 | 民族 | 总分 | 说明 | |
---|---|---|---|---|
0 | 张三 | 藏 | 560 | 录取 |
1 | 李四 | 汉 | 470 | 复读 |
2 | 王五 | 回 | 500 | 复读 |